package rwi.informationsystem.server;

import org.osgi.service.http.HttpService;

import rwi.informationsystem.core.interfaces.IInformationSystem;
import rwi.informationsystem.core.variables.RwiCommunication;
import rwi.informationsystem.internal.server.RWI_Servlet_register;

public class Manager {
	private HttpService http;
	private IInformationSystem is;
	private String servletAlias;

	public void setHttp(HttpService value) {
		this.http = value;
	}

	public void setStoreService(IInformationSystem value) {
		this.is = value;
	}

	protected void shutdown() {
		http.unregister(servletAlias);
	}

	protected void startup() {
		try {
			// /http://localhost:8081
			String servletRoot = "/"+RwiCommunication.OBJECT_SERVLET;
			servletAlias = servletRoot;

			RWI_Servlet_register servlet = new RWI_Servlet_register(is);

			servlet.init();
			http.registerServlet(servletAlias, servlet, null, null);
			System.out.println("Service Registered.");
		} catch (Exception e) {
			System.out.println("Error while registering Service.");
		}
	}
}
